package ubiqweb.spring3.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ubiqweb.spring3.model.Payment;
import ubiqweb.spring3.service.PaymentService;

import ubiqweb.spring3.model.LoginDetails;
import ubiqweb.spring3.service.LoginService;

@Controller
@RequestMapping("/payments")
public class PaymentController {

	@Autowired
	private PaymentService paymentService;
	
	@Autowired
	private LoginService loginService;
	
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView listPayments(HttpSession session) {
		String userId = session.getAttribute("sessionUsrID").toString();
		List<LoginDetails> loginDetails = loginService.getListLoginDetails(userId);
		Map<String, Object> model = new HashMap<String, Object>();
		if(loginDetails.get(0).getUserType().equals("USR"))
			model.put("payments",  paymentService.listPayments(userId));
		else
			model.put("payments",  paymentService.listPayments());
		
		return new ModelAndView("paymentList", model);
	}

}